<template>
  <div class="page-container">
    <!--工具栏-->
    <div class="toolbar" style="padding-top:10px;">
      <el-form :inline="true" :model="filters" :size="size" ref="filters" label-width="120px">
        <el-form-item prop="userName" label="活动名称">
          <el-input v-model="filters.userName" placeholder="活动名称"></el-input>
        </el-form-item>
        <el-form-item prop="userName" label="活动分组">
          <el-select v-model="filters.userName1" placeholder="活动分组" style="width:215px">
            <el-option v-for="item in statusList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="userName" label="创建人">
          <el-input v-model="filters.userName2" placeholder="创建人"></el-input>
        </el-form-item>
        <el-form-item prop="userName" label="审批人">
          <el-input v-model="filters.userName3" placeholder="审批人"></el-input>
        </el-form-item>
        <el-form-item prop="userName" label="活动开始时间">
          <el-date-picker
            v-model="filters.userName4"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions">
          </el-date-picker>
      </el-form-item>
        <el-form-item prop="userName" label="活动结束时间">
          <el-date-picker
            v-model="filters.userName5"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>
        <el-row>
          <el-form-item>
            <kt-button icon="fa fa-search" :label="$t('action.search')" type="primary" @click="findPage(null)"/>
          </el-form-item>
          <el-form-item>
            <kt-button :label="$t('action.reset')" type="primary" @click="resetForm('filters')"/>
          </el-form-item>

          <el-form-item style="float: right">
            <el-button-group>
              <el-tooltip content="刷新" placement="top">
                <el-button icon="fa fa-refresh" @click="findPage(null)"></el-button>
              </el-tooltip>
              <el-tooltip content="列显示" placement="top">
                <el-button icon="fa fa-filter" @click="displayFilterColumnsDialog"></el-button>
              </el-tooltip>
              <el-tooltip content="导出" placement="top">
                <el-button icon="fa fa-file-excel-o" @click="downloadExcel"></el-button>
              </el-tooltip>
            </el-button-group>
          </el-form-item>
        </el-row>
      </el-form>
    </div>

    <div class="toolbar" style="float:right;padding-top:10px;padding-right:15px;">
      <!--表格显示列界面-->
      <table-column-filter-dialog
        ref="tableColumnFilterDialog"
        :columns="columns"
        @handleFilterColumns="handleFilterColumns"
      ></table-column-filter-dialog>
    </div>

    <!--表格内容栏-->
    <cy-table
      :height="350"
      :data="pageResult"
      :columns="filterColumns"
      :showBatchDelete="false"
      :showDeleteOperation="true"
      :showSelection="false"
      :showEditOperation="false"
      @findPage="findPage"
      @handleDelete="handleDelete"
      ref="CyTable"
    ></cy-table>

  </div>
</template>

<script>
  import CyTable from "@/views/Core/JicTable";
  import KtButton from "@/views/Core/KtButton";
  import {format, formatWithSeperator} from "@/utils/datetime";
  import TableColumnFilterDialog from "@/views/Core/TableColumnFilterDialog";

  export default {
    components: {
      CyTable,
      KtButton,
      TableColumnFilterDialog
    },
    data() {
      return {
        statusList: [
          {
            id: "0",
            name: "满额减"
          },
          {
            id: "1",
            name: "满额折"
          },
          {
            id: "2",
            name: "满额减运费"
          },
        ],
        size: "small",
        text: '查看',
        disabledBoolean: true,
        filters: {
          username: '',
          username1: '',
          username2: '',
          username3: '',
          username4: '',
          username5: '',
          res: {
            total: 4,
            code: "0000",
            rows: [
              {
                id: " 1051",
                val1: "1051",
                val2: "满额折促销",
                val3: "满额折",
                val4: "2020-03-10 00:00:00 - 2020-04-25 00:00:00",
                val5: "2020-06-10 00:00:00 - 2020-07-25 00:00:00",
                val6: "xixi",
                val7: "后台管理员",
                val8: "后台管理员",
              },
              {
                id: " 1052",
                val1: "满额减促销",
                val2: "满额减促销",
                val3: "满额减",
                val4: "2020-03-21 00:00:00-2020-04-29 00:00:00",
                val5: "2020-05-21 00:00:00-2020-07-29 00:00:00",
                val6: "feiyada",
                val7: "后台管理员",
                val8: "后台管理员",
              },
              {
                id: " 1053",
                val1: "满额减促销",
                val2: "满额减促销",
                val3: "满额减",
                val4: "2020-03-21 00:00:00-2020-04-29 00:00:00",
                val5: "2020-05-21 00:00:00-2020-05-29 00:00:00",
                val6: "hahah",
                val7: "后台管理员",
                val8: "后台管理员",
              },
              {
                id: " 1054",
                val1: "满额减促销",
                val2: "满额减促销",
                val3: "满额减",
                val4: "2020-03-20 00:00:00-2020-03-21 00:00:00",
                val5: "2020-06-20 00:00:00-2020-06-21 00:00:00",
                val6: "axiba",
                val7: "后台管理员",
                val8: "后台管理员",
              }
            ]
          }
        },
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
          optionSex: [{id: 0, name: '男'}, {id: 1, name: '女'}],
          memberTypeList: [],
          columns: [
            {prop: "id", label: "活动ID", minWidth: 80},
            {prop: "val2", label: "活动名称", minWidth: 100},
            {prop: "val3", label: "活动分组", minWidth: 100},
            {prop: "val4", label: "活动开始时间", minWidth: 150},
            {prop: "val5", label: "活动结束时间", minWidth: 150},
            {prop: "val6", label: "营销对象类型", minWidth: 80},
            {prop: "val7", label: "创建人", minWidth: 120},
            {prop: "val8", label: "审批人", minWidth: 120},
          ],
          filterColumns: [],
          pageRequest: {pageNum: 1, pageSize: 10},
          pageResult: {},
          operation: false, // true:查看, false:编辑
          editDialogVisible: false, // 新增编辑界面是否显示
          editLoading: false,
          dataFormRules: {},
          // 新增编辑界面数据
          dataForm: {
            id: "",
            val1: "",
            val2: "",
            val3: "",
            val4: "",
            val5: "",
            val6: "",
            val7: "",
            val8: "",
            remark: "",
          }
        };
    },
      methods: {
        // 获取分页数据
        findPage: function (data) {
          this.$refs.CyTable.findPageStaticState(this.filters);
        }
      ,
        // 显示新增界面
        handleAdd: function () {
          this.editDialogVisible = true;
          this.operation = true;
          this.resetForm("dataForm");
        }
      ,
        // 显示查看界面
        handleEdit: function (params) {
          this.editDialogVisible = true;
          this.disabledBoolean = false;
          this.operation = false;
          this.$nextTick(function () {
            this.dataForm = Object.assign({}, params.row);
          });
        }
      ,
        // 显示编辑界面
        handleDetail: function (params) {
          this.editDialogVisible = true;
          this.disabledBoolean = true;
          this.operation = true;
          this.$nextTick(function () {
            this.dataForm = Object.assign({}, params.row);
          });
        }
      ,
        // 编辑
        submitForm: function () {
          this.$refs.dataForm.validate(valid => {
            if (valid) {
              this.$confirm("确认提交吗？", "提示", {}).then(() => {
                this.$message({message: "操作成功", type: "success"});
                this.editDialogVisible = false;
              });
            }
          });
        }
      ,
        // 时间格式化
        dateFormat: function (row, column, cellValue, index) {
          return format(row[column.property]);
        }
      ,
        resetForm(formName)
        {
          if (this.$refs[formName] != undefined) {
            this.$refs[formName].resetFields();
            this.findPage(null);
          }
        }
      ,
        // 处理表格列过滤显示
        displayFilterColumnsDialog: function () {
          this.$refs.tableColumnFilterDialog.setDialogVisible(true);
        }
      ,
        // 处理表格列过滤显示
        handleFilterColumns: function (data) {
          this.filterColumns = data.filterColumns;
          this.$refs.tableColumnFilterDialog.setDialogVisible(false);
        }
      ,
        // 处理表格列过滤显示
        initColumns: function () {
          var temp = [];

          $.each(this.columns, function (key, val) {
            temp.push(val);
          });
          this.filterColumns = temp;
        }
      ,
        // 批量删除
        handleDelete: function (data) {
          this.$message({message: "操作成功", type: "success"});
        }
      ,
        //列表下载
        downloadExcel()
        {
          this.$confirm("确定下载列表文件?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
            .then(() => {
              let filename = "系统参数下载";
              this.$refs.CyTable.exportData(
                this.filters,
                this.filterColumns,
                filename
              );
            })
            .catch(() => {
            });
        }
      }
    ,
      mounted()
      {
        this.initColumns();
      }
    };
</script>

<style scoped>
  .el-icon-plus {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }

  .el-icon-plus .el-upload:hover  {
    border-color:   #409EFF;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px !important;
    text-align: center;
  }

  .avatar {
    width: 178px;
    height: 178px;
    display: block;
  }
</style>
